﻿//-----------------------------------------------------------------------
// <copyright file="ColorPickerFieldDefinition.cs" company="Jamie Knight">
// Copyright (c) Jamie Knight. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Windows;
using System.Windows.Data;
using DevKnightlie.WPF.AutoForm.FieldDefinitions;
using Xceed.Wpf.Toolkit;

namespace DevKnightlie.WPF.AutoForm.WPFToolkit.FieldDefinitions
{
    /// <summary>
    /// Field definition which creates a ColorPicker control
    /// </summary>
    public class ColorPickerFieldDefinition: BaseFieldDefinition
    {
        #region Properties

        /// <summary>
        /// Sets or returns the name of a property to bind the ColorPickers SelectedColorText property to
        /// </summary>
        public String ColorTextPropertyName { get; set; }

        #endregion

        #region Methods

        public override void BuildInputControl()
        {
            ColorPicker colorPicker = new ColorPicker()
            {
                HorizontalContentAlignment = HorizontalAlignment.Left,
                VerticalContentAlignment = VerticalAlignment.Center
            };
            Binding colorBinding = new Binding(PropertyName);
            BindingOperations.SetBinding(colorPicker, ColorPicker.SelectedColorProperty, colorBinding);
            if (!String.IsNullOrWhiteSpace(ColorTextPropertyName))
            {
                Binding colorTextBinding = new Binding(ColorTextPropertyName);
                BindingOperations.SetBinding(colorPicker, ColorPicker.SelectedColorTextProperty, colorTextBinding);
            }
            SetupEnabledBinding(colorPicker);
            InputControl = ContainerControl = colorPicker;
        }

        #endregion
    }
}
